﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program
    {
        enum enrole
        {
            刘备 = 1,
            孙权 = 2,
            曹操 = 3
        }
        enum enMora
        {
            石头 = 1,
            剪刀 = 2,
            布 = 3
        }
        static void Main(string[] args)
        {
            Console.WriteLine("-----------欢迎进入游戏世界-----------" + "\n");
            Console.WriteLine("************************");
            Console.WriteLine("********猜拳开始********");
            Console.WriteLine("************************");
            Console.WriteLine("出拳规则：1.剪刀2.石头3.布");
            Console.WriteLine("请选择对方的角色（1:刘备2.孙权3.曹操）");
            int numname = int.Parse(Console.ReadLine());
            string npcstr = Enum.GetName(typeof(enrole), numname); //NPC姓名 npcstr

            Role role = new Role(npcstr);                   //获取名字后传入类重写
            Console.WriteLine("请输入您的姓名");             // 玩家姓名 playname
            string playname = Console.ReadLine();

            Console.WriteLine(playname + " VS " + npcstr);

            Console.WriteLine("是否开始游戏（y/n）");
            char char1 = Convert.ToChar(Console.ReadLine());
            if (char1 == 'y' || char1 == 'Y')
            {
                WinMora(role, npcstr, playname);
            }
            else if(char1 == 'n' || char1 == 'N')
            {
                Console.WriteLine("退出游戏");
            }
            Console.WriteLine("要开始下一局游戏吗？(y/n)");
            char char3 = Convert.ToChar(Console.ReadLine());
            if (char3 == 'y' || char3 == 'Y')
            {
                WinMora(role, npcstr, playname);
            }
            else if (char3 == 'n' || char3 == 'N')
            {
                Console.WriteLine("退出程序");
                System.Environment.Exit(0);
            }
        }

        private static void WinMora(Role role, string npcstr, string playname)
        {
            int draw = 0;
            int NPCwin = 0;
            int Playwin = 0;

            while (true)
            {
                Console.WriteLine("请出拳1.石头2.剪刀3.布请输入数字（请输入相应的数字）");
                int Moranum = int.Parse(Console.ReadLine());
                string playMora = Enum.GetName(typeof(enMora), Moranum); //获取用户输入的数字转化为相应的枚举里的值

                Console.WriteLine(playname + " : 出拳： " + playMora);
                role.Write();

                if (role.StrMora == playMora)
                {
                    Console.WriteLine("平局，下次再会");
                    draw = draw + 1;
                }
                else if (playMora == "石头" && role.StrMora == "剪刀" || playMora == "布" && role.StrMora == "石头" || playMora == "剪刀" && role.StrMora == "布")
                {
                    Console.WriteLine("恭喜您，胜利");
                    Playwin = Playwin + 1;
                }
                else if (role.StrMora == "剪刀" && playMora == "布" || role.StrMora == "石头" && playMora == "剪刀" || role.StrMora == "布" && playMora == "石头")
                {
                    Console.WriteLine("这也会输");
                    NPCwin = NPCwin + 1;
                }
                else if (playMora != "石头" || playMora != "剪刀" || playMora != "布")
                {
                    NPCwin = NPCwin + 1;
                    Console.WriteLine("出拳不符合规则");
                }
                
                Console.WriteLine("是否开始下一局(y/n)");
                char char2 = Convert.ToChar(Console.ReadLine());
                if (char2 == 'y' || char2 == 'Y')
                {
                }
                else if(char2 == 'n' || char2 == 'N')
                {
                    Console.WriteLine("结束游戏");
                    Console.WriteLine("===========================");
                    Console.WriteLine(playname + " VS " + npcstr);
                    Console.WriteLine("对战次数" + (Playwin + NPCwin + draw));
                    Console.WriteLine("姓名     得分");
                    Console.WriteLine($"{playname}     {Playwin}");
                    Console.WriteLine($"{npcstr}     {NPCwin}");
                    if (Playwin > NPCwin)
                    {
                        Console.WriteLine( "玩家 "+playname+" 胜出，恭喜恭喜");
                    }
                    else if (NPCwin > Playwin)
                    {
                        Console.WriteLine( "电脑"+ npcstr+"胜出，不错呦");
                    }
                    else
                    {
                        Console.WriteLine("平局");
                    }
                    break;
                }
                

            }
        }
    }

    
}


